<?php
/* SVN FILE: $Id: item.php 222 2009-09-16 20:07:22Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Using an Item
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 222 $
* @lastrevision $Date: 2009-09-16 20:07:22 +0000 (Wed, 16 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-16 20:07:22 +0000 (Wed, 16 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_public/inventory/item.php $
*/

class public_ibmarket_inventory_item extends marketPublicCommand
{
	public function doExecute( ipsRegistry $registry )
	{
		if($this->memberData['member_id'] == 0 || !$this->memberData['g_market_use'])
		{
			$this->registry->getClass('output')->showError('no_permission');
		}
		
		$inventoryItems = marketRegistry::getInventoryItem($this->memberData['member_id']);
		
		if(!is_array($inventoryItems[$this->request['item']]))
		{
			$this->registry->getClass('output')->showError('no_permission');
		}
		
		$return = marketRegistry::getItem($this->caches['market_items'][$inventoryItems[$this->request['item']]['item']])->publicUseItem($inventoryItems[$this->request['item']]);
		if(is_string($return))
		{
			$template = $this->registry->getClass('output')->getTemplate('ibmarket')->ibmarketHTMLWrapper($return);
			
			$this->registry->getClass('output')->setTitle( $this->settings['market_name'] );
			$this->registry->getClass('output')->addContent( $template );
			
			$this->registry->getClass('output')->sendOutput();
		}
		elseif($return || is_null($return))
		{
			marketRegistry::getItem($this->caches['market_items'][$inventoryItems[$this->request['item']]['item']])->writeLog($inventoryItems[$this->request['item']],"No Message");
			marketRegistry::getItem($this->caches['market_items'][$inventoryItems[$this->request['item']]['item']])->deleteItems($inventoryItems[$this->request['item']]);
		}
		
		$this->registry->getClass('output')->redirectScreen( $this->lang->words['item_used'], $this->settings['base_url_with_app'] . "module=inventory" );
	}
}